package com.kehutong.admin.controler;

import com.kehutong.admin.entity.Invoice;
import com.kehutong.common.util.Token;
import org.coraframework.authz.HasPermission;
import org.coraframework.inject.Inject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;
import org.coraframework.orm.jdbc.JdbcSession;

@MvcAction
@ReqMapping("/admin/sys/invoice")
public class InvoiceController {

    @Inject
    private JdbcSession jdbcSession;

    @Bean(newInstance = true, copy = true)
//    @HasPermission("sys:invoice:edit")
    @ReqMapping("/save")
    public Object save(Token token, Invoice invoice) {
        invoice.setId(token.getCompanyNo());
        invoice.setUpdateName(token.getUsername());
        invoice.setCreateName(token.getUsername());

    	jdbcSession.insert(invoice);

        return Result.success();
    }

    @Bean(copy = true)
//    @HasPermission("sys:invoice:edit")
    @ReqMapping("/update")
    public Object update(Token token, Invoice invoice) {
        invoice.setUpdateName(token.getUsername());
    	jdbcSession.updateById(invoice);

        return Result.success();
    }

//    @HasPermission("sys:invoice:view")
    @ReqMapping("/get")
    public Object getById(Invoice invoice) {
        return invoice;
    }
}
